package com.ccmusic.dao.impl;

import java.util.List;
import com.ccmusic.dao.SingerDao;
import com.ccmusic.entity.Singer;

/**
 * 
 * @author 赖永昌 2019.3.27
 *
 */
public class SingerDaoImpl extends BaseDao implements SingerDao {

	/**
	 * 根据音乐id删除歌手
	 * 
	 * @author zhujz
	 * @param mid
	 *            歌曲id
	 * @return 删除成功返回true；删除失败返回false
	 */
	public boolean delSingerByMid(String mid) {
		String sql = "delete from singer where mid=?";
		int rsCode = this.execute(sql, mid);
		return rsCode > 0;
	}

	// 增加歌手
	public boolean addSinger(Singer singer) {
		String sql = "insert into singer values(null,?,?,?)";
		int n = this.execute(sql, singer.getMid(), singer.getSingerId(), singer.getSname());
		if (n > 0)
			return true;
		return false;
	}

	// 删除 根据歌手名字
	public boolean deleteSingerByName(String sname) {
		String sql = "delete from singer where sname=?";
		int n = this.execute(sql, sname);
		if (n > 0)
			return true;
		return false;
	}

	// 查询 模糊查询
	public List<Singer> getSingerLikeName(String likename) {
		String sql = "select * from singer where sname like ?";
		List<Singer> list = (List<Singer>) this.select(sql, Singer.class, "%" + likename + "%");
		if (list.size() > 0) {
			return list;
		}
		return null;
	}

	// 查询 全表
	public List<Singer> getAllSinger() {
		String sql = "select * from singer ";
		List<Singer> list = (List<Singer>) this.select(sql, Singer.class);
		if (list.size() > 0) {
			return list;
		} else
			return null;
	}

}
